package item_model

import "base"

type Manager struct {
	Data     map[base.AssetItemId]*Item
	Inserted map[base.AssetItemId]bool
	Updated  map[base.AssetItemId]bool
	Deleted  map[base.AssetItemId]bool

	changes map[base.AssetItemId]int64
}

func NewManager() *Manager {
	result := new(Manager)
	result.Data = make(map[base.AssetItemId]*Item)
	result.Inserted = make(map[base.AssetItemId]bool)
	result.Updated = make(map[base.AssetItemId]bool)
	result.Deleted = make(map[base.AssetItemId]bool)

	result.changes = make(map[base.AssetItemId]int64)

	return result
}

func (manager *Manager) OnChange(itemId base.AssetItemId, itemCount int64) {
	manager.changes[itemId] += itemCount
}

func (manager *Manager) ResetChanges() (result map[base.AssetItemId]int64) {
	result = manager.changes
	manager.changes = make(map[base.AssetItemId]int64)

	return
}
